package me.pinion.controller;

import me.pinion.Log;
import me.pinion.model.User;
import me.pinion.service.Service;

import java.lang.reflect.Field;


public abstract class Controller extends com.jfinal.core.Controller {
    public Controller(){
        Field[] fields =this.getClass().getDeclaredFields();
        for (int i=0;i < fields.length; i++){
            Field field = fields[i];
            Class clazz = field.getType();
            if(Service.class.isAssignableFrom(clazz) && clazz != Service.class){
                try {
                    this.setProperty(field.name, Service.getInstance(clazz))
                } catch (IllegalAccessException e) {
                    Log.e(e);
                }
            }
        }
    }

    protected User curUser(){
        return User.dao.findById(this.<User>getSessionAttr("user").getId());
    }
}
